<%@ page import="user.User" %>
<%@ page import="com.example.demo_text.UserDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String idStr = request.getParameter("id");
    int id = 0;
    if (idStr != null && !idStr.isEmpty()) {
        try {
            id = Integer.parseInt(idStr);
        } catch (NumberFormatException ignored) {}
    }

    User teacher = UserDAO.getUserById(id);
    if (teacher == null) {
        response.sendRedirect("admitmanageTeacher.jsp");
        return;
    }
%>

<html>
<head>
    <title>编辑教师信息</title>
    <style>
        /* 全局样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
            background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 40px 20px;
            color: #333;
        }

        .card {
            background: white;
            width: 100%;
            max-width: 600px;
            padding: 30px 25px;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
            text-align: center;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        }

        h2 {
            text-align: center;
            margin-bottom: 24px;
            font-weight: 600;
            color: #374151;
        }

        label {
            display: block;
            text-align: left;
            margin-top: 15px;
            margin-bottom: 5px;
            font-weight: 500;
        }

        input[type="text"],
        input[type="email"],
        input[type="number"] {
            width: 100%;
            padding: 10px 15px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 6px;
        }

        button {
            width: 100%;
            padding: 12px;
            background-color: #d1ecf1;
            color: #15576b;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s, color 0.3s;
        }

        button:hover {
            background-color: #aee2eb;
            color: #0f3d4d;
        }

        a.back-link {
            display: block;
            text-align: center;
            margin-top: 20px;
            color: #3498db;
            text-decoration: underline;
            font-size: 14px;
        }

        a.back-link:hover {
            color: #2980b9;
        }
    </style>
</head>
<body>

<div class="card">
    <h2>🧑‍🏫 编辑 <%= teacher.getUsername() %> 的信息</h2>
    <form action="AdmitUpdateTeacherServlet" method="post">
        <input type="hidden" name="id" value="<%= teacher.getId() %>" />

        <label for="username">用户名：</label>
        <input type="text" id="username" name="username" value="<%= teacher.getUsername() %>" required />

        <label for="email">邮箱：</label>
        <input type="email" id="email" name="email" value="<%= teacher.getEmail() %>" required />

        <label for="age">年龄：</label>
        <input type="number" id="age" name="age" value="<%= teacher.getAge() %>" min="0" max="150" required />

        <button type="submit">保存更改</button>
    </form>
    <a href="admitmanageTeacher.jsp" class="back-link">返回教师列表</a>
</div>

</body>
</html>
